package com.xiatl.cgi.client;

import com.alibaba.fastjson.JSONObject;
import com.xiatl.cgi.server.cgi.utils.HttpRequestUtil;
import com.xiatl.cgi.server.cgi.utils.SignUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 客户端测试控制器
 */
@RestController
@RequestMapping("/client")
public class ClientTestController {

    @RequestMapping("/test")
    public String test() {

        String appKey = "username1";
        String appSecret = "12345678";
        String timestamp = new Date().getTime() + "";

        String path = "/server/test";

        // 参数
        JSONObject params = new JSONObject();
        params.put("userNo", "USER00000001");
        // 签名
        String sign = SignUtil.sign(params, path, appSecret, timestamp);
        // 拼装请求url
        String url = "http://localhost:8080" + path;
        // 设置请求header
        Map<String, String> headers = new HashMap<>();
        headers.put("appKey", appKey);
        headers.put("sign", sign);
        headers.put("timestamp", timestamp);
        // 发起请求
        String result = HttpRequestUtil.post(url, params, headers);
        return result;
    }
}
